// ROICopy.cpp : implementation file
//

#include "stdafx.h"
#include "Measure.h"
#include "ROICopy.h"
#include "afxdialogex.h"


// CROICopy dialog

IMPLEMENT_DYNAMIC(CROICopy, CDialogEx)

CROICopy::CROICopy(CWnd* pParent /*=NULL*/)
	: CDialogEx(CROICopy::IDD, pParent)
  , element_name_(_T(""))
{

}

CROICopy::~CROICopy()
{
}

void CROICopy::DoDataExchange(CDataExchange* pDX)
{
  CDialogEx::DoDataExchange(pDX);
  DDX_Control(pDX, IDC_LIST_STATION, wnd_station_list_);
  DDX_Control(pDX, IDC_COMBO_ELEMENT, wnd_element_combo_);
  DDX_CBString(pDX, IDC_COMBO_ELEMENT, element_name_);
}


BEGIN_MESSAGE_MAP(CROICopy, CDialogEx)
  ON_BN_CLICKED(IDOK, &CROICopy::OnBnClickedOk)
  ON_BN_CLICKED(IDCANCEL, &CROICopy::OnBnClickedCancel)
  ON_LBN_SELCHANGE(IDC_LIST_STATION, &CROICopy::OnStationSelChange)
END_MESSAGE_MAP()


// CROICopy message handlers


void CROICopy::OnBnClickedOk()
{
  CDialogEx::OnOK();
}


void CROICopy::OnBnClickedCancel()
{
  CDialogEx::OnCancel();
}


BOOL CROICopy::OnInitDialog()
{
  CDialogEx::OnInitDialog();

  CMeasureProject &mp = theApp.project();
  for (int s=0; s<mp.num_stations(); ++s) {
    wnd_station_list_.AddString(mp.station(s)->Name().c_str());
    if (mp.station(s)->Name()==StationName) {
      wnd_station_list_.SetCurSel(s);
      OnStationSelChange();
    }
  }

  return TRUE;
}


void CROICopy::OnStationSelChange()
{
  int curSel = wnd_station_list_.GetCurSel();
  CMeasureStation *ms = theApp.project().station(curSel);
  ASSERT(ms!=NULL);

  wnd_element_combo_.ResetContent();
  if (ms->num_arcs()==0) {
    wnd_element_combo_.EnableWindow(FALSE);
    return;
  }

  wnd_element_combo_.EnableWindow(TRUE);
  for (int a=0; a<ms->num_arcs(); ++a) {
    wnd_element_combo_.AddString(ms->arc(a).c_str());
  }
  wnd_element_combo_.SetCurSel(0);
}